"use strict";
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
    for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
        to[j] = from[i];
    return to;
};
//适配器模式典型应用之promisify
var fs = require('fs');
// fs.readFile('../uitils/1.text', 'utf8', (err: any, data: any): void => {
//   if (!err) {
//     console.log(data);
//   };
//   console.log('err:', err);
// });
//promisify适配器
function promisify(callback) {
    return function () {
        var args = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            args[_i] = arguments[_i];
        }
        return new Promise(function (resolve, reject) {
            console.log.apply(console, args);
            callback.apply(void 0, __spreadArray(__spreadArray([], args), [function (err, data) {
                    if (!err) {
                        return resolve(data);
                    }
                    ;
                    return reject(err);
                }]));
        });
    };
}
;
// 通过适配器将异步转成同步
var readFileFn = promisify(fs.readFile);
readFileFn('../../uitils/2.text', 'utf8').then(function (res) {
    console.log('读取成功=', res);
}, function (err) {
    console.log('读取失败=', err);
});
